package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-08-16
 * Time: 14:46
 */
class Student{
    //私有属性name
    private String name = "bit";
    //公有属性age
    public int age = 18;
    //不带参数的构造方法
    public Student(){
        System.out.println("Student()");
    }
    private Student(String name,int age) {
        this.name = name;
        this.age = age;
        System.out.println("Student(String,name)");
    }
    private void eat(){
        System.out.println("i am eat");
    }
    public void sleep(){
        System.out.println("i am pig");
    }
    private void function(String str) {
        System.out.println(str);
    } @
            Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        //要么交给jvm，要么自己捕捉
        Class<?> c1 = null;
        try{
            c1 = Class.forName("demo1.Student");//关注forName的返回类型，受查时异常
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }

        Class<?> c2 = Student.class;

        Student student = new Student();
        Class<?> c3 = student.getClass();//为了生成一个Class对象还要在去生成一个对象，不好

        System.out.println(c1 == c2);
        System.out.println(c1 == c3);
        //结论：这三个c生成都是同一个对象
    }



}
